const { BusiError, SysError } = require('../exception/exception');
const payService = require("../service/PayService");
const redisConst = require("../const/redisConst");
const redis = require("../dao/redis");

class WithdrawCashQueryJob {
    constructor() {
    }

    async query(date){
        const limitKey = redisConst.PAY_WITHDRAW_QUERY_LOCK;
        let ok = await redis.lock(limitKey, 1, 50);
        if (!ok){
            return;
        }
        console.logw("withdraw cash query start>>>>>>>>>>>>>>>>>>>>>>");

        let res = await payService.queryOrdersByOrderType("OT003");
        for (let i = 0; i < res.length; i++) {
            let item = res[i];
            try {
                await payService.getService(item.pay_channel).withdrawQuery(item.out_trade_no);
            }catch (e) {
                console.logw("withdraw cash err:", item.out_trade_no);
                console.log(e);
                continue;
            }
            console.logw("withdraw cash success:", item.out_trade_no);
        }

        console.logw("withdraw cash query end<<<<<<<<<<<<<<<<<<<<<<<<");
    }
}


let withdrawCashQueryJob = new WithdrawCashQueryJob();
module.exports = withdrawCashQueryJob;